package com.zzptc.easyshop.factory;

import com.zzptc.easyshop.dao.IDAO;
import com.zzptc.easyshop.util.MyUtil;

import java.util.Map;

public class DaoFactoryImp implements IFactory{
    //饿汉式
    private static DaoFactoryImp daoFactoryImp=new DaoFactoryImp();
    private DaoFactoryImp(){}
    public static DaoFactoryImp getInstance(){
        return daoFactoryImp;
    }


    @Override
    public IDAO createDAO(String type) throws Exception {
        Map<String,String> map=MyUtil.readXML("daoconfig.xml");
       String daostring= map.get(type);//com.zzptc.easyshop.dao.UserDao
        IDAO dao= (IDAO) Class.forName(daostring).newInstance();
        return dao;
    }

    public static void main(String[] args) {
        try {
            DaoFactoryImp.getInstance().createDAO("userdao");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
